
const getZhiHuList = async (id) => {
  if(!window.utools)return[];
  let res = await window.utools.ubrowser
  .goto("https://www.zhihu.com/knowledge-plan/hot-question/hot/0/day")
  // .devTools('right')
  .wait('div[role="listitem"] ~ div', 60000)
  .wait(200)
  .evaluate(() => {
    let hotList = [...document.querySelector('[role="listitem"]').parentElement.children];
    hotList.shift();
    hotList.pop();
    let arr = hotList.map((item, index) => {
      const infos = item.querySelector('div').querySelectorAll(':scope > div');
      let url = infos[0].querySelector('a').href;
      let articleNumber = index + 1;
      let bool = infos[0].querySelector('a').querySelector('div').querySelector('div');
      let str = infos[0].querySelector('a').innerText;
      let articleDetail = bool ? str.slice(2) : str;
      let hotNumber = infos[2].querySelectorAll(':scope > div')[1].innerText.slice(1);

      return {
        url,
        index: articleNumber,
        detail: articleDetail,
        hot: hotNumber,
      };
    });
    return arr;
  })
  .run({ show: false });
  // .run({ width: 1300, height: 1000 });
  window.utools.clearUBrowserCache();
  return {
    id,
    list: res[0]
  }
};


export { getZhiHuList };